package com.imay.live.activity.profit;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.imay.base.activity.BaseActivity;
import com.imay.base.util.StringUtil;
import com.imay.live.R;
import com.imay.live.activity.authentication.UserSignActivity;
import com.imay.live.activity.recharge.BuyDiamondsActivity;
import com.imay.live.activity.recharge.MyRechargeHistoryActivity;
import com.imay.live.adapter.BuyLinearAdapter;
import com.imay.live.analytics.MobclickAgent;
import com.imay.live.cache.UserInfoCache;
import com.imay.live.helper.DialogFragmentHelper;
import com.imay.live.helper.EventHelper;
import com.imay.live.model.UserInfoModel;
import com.imay.live.model.WithdrawInfoModel;
import com.imay.live.proto.MessageId;
import com.imay.live.proto.ProtoResult;
import com.imay.live.proto.Result;
import com.imay.live.proto.ResultCode;
import com.imay.live.proto.helper.ProtoCallBack;
import com.imay.live.proto.helper.ProtoHttpFactory;
import com.imay.live.proto.helper.ProtoRequestHelper;
import com.imay.live.utils.ToastUtil;
import com.imay.live.view.custom.EditTextView;
import com.imay.live.view.custom.MoneyTextView;
import com.imay.live.view.custom.ProfitTitle;
import com.imay.live.view.custom.ReallyNameView;
import com.imay.live.view.custom.RechargeTitle;
import com.imay.live.view.recyclerview.WrapContentLinearLayoutManager;
import com.imay.tbas_api.IMYTBASObject;

import org.json.JSONObject;

import static com.imay.live.proto.ResultCode.CodeSuccess;

/**
 * create by lzx
 * 我的->我的收益
 */
public class IncomeActivity extends BaseActivity {
    private java.text.DecimalFormat df = new java.text.DecimalFormat("#####0.00");
    private RecyclerView mrecyclerView;
    private BuyLinearAdapter mAdapter;
    private EditTextView meiliView;//魅力值
    private EditTextView editTextView;//账号
    private MoneyTextView moneyTextView;//到账金额
    private double maxmonoy;
    public static final int MINMEILI = 300;
    public static final int RECODE = 0x300;
    public static final int RECARDCODE = 0x400;
    ReallyNameView phoneView;
    ReallyNameView reallyNameView;
    ExchangeButton exchangeprofit;
    ExchangeButton exchangeButton;
    private IMYTBASObject mSocketNotify;
    private IMYTBASObject mSocketNotifySing;
    private WithdrawInfoModel withdrawInfoModel;
    private FrameLayout frame_layout;

    public static void start(Context context) {
        Intent starter = new Intent(context, IncomeActivity.class);
//        starter.putExtra();
        context.startActivity(starter);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_income;
    }


    @Override
    protected void initView(Bundle savedInstanceState) {
        setTitle(getString(R.string.mine_income));
        getTitleBar().addRightTextView(getResources().getString(R.string.get_history));
        getTitleBar().setRightTextOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                MyRechargeHistoryActivity.start(IncomeActivity.this, 1);
                MobclickAgent.onEvent(IncomeActivity.this,"income_click_cash");
            }
        });
        mrecyclerView = $(R.id.rcv_charge);
        frame_layout = $(R.id.frame_layout);
        WrapContentLinearLayoutManager wrapContentLinearLayoutManager
                = new WrapContentLinearLayoutManager(this);
        mrecyclerView.setLayoutManager(wrapContentLinearLayoutManager);
        mAdapter = new BuyLinearAdapter(null);
        mAdapter.bindToRecyclerView(mrecyclerView);
        LoadData();
        registerSocketNotifySING();
        registerSocketNotify();
        MobclickAgent.onEvent(IncomeActivity.this,"income_open");
    }

    RechargeTitle rechargeTitle;
    ProfitTitle profitTitle;
    TextView bottomTips;

    void init(final WithdrawInfoModel withdrawInfoModel) {
        this.withdrawInfoModel = withdrawInfoModel;
        if (rechargeTitle == null) {
            rechargeTitle = new RechargeTitle(IncomeActivity.this);
            mAdapter.addHeaderView(rechargeTitle);
        }
        rechargeTitle.setTitleText(getResources().getString(R.string.profitlast));

        rechargeTitle.setText(withdrawInfoModel.getMeili());
        maxmonoy = withdrawInfoModel.getMeili() * withdrawInfoModel.getMeiliToMoneyRatio() / 100.00;
//        maxmonoy = withdrawInfoModel.isItemDouble() ? money * 2 : money;
        if (profitTitle == null) {
            profitTitle = new ProfitTitle(this);
            mAdapter.addHeaderView(profitTitle);
        }
        profitTitle.setText(df.format(maxmonoy));
        if (!withdrawInfoModel.isRealNameVerify()) {
            if (reallyNameView == null) {
                reallyNameView = new ReallyNameView(this, 0);
                mAdapter.addHeaderView(reallyNameView);
            }

        }
        if (!withdrawInfoModel.isBindPhone()) {
            if (phoneView == null) {
                phoneView = new ReallyNameView(this, 1);
                mAdapter.addHeaderView(phoneView);
            }
        }
        if (editTextView == null) {
            editTextView = new EditTextView(this, 0);
            editTextView.setOnEditorActionListener(new TextView.OnEditorActionListener() {
                @Override
                public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                    if (actionId == EditorInfo.IME_ACTION_NEXT) {
                        meiliView.setFocusable();
                        return true;
                    }
                    return false;
                }
            });
            editTextView.addTextChangedListener(new TextWatcher() {
                @Override
                public void beforeTextChanged(CharSequence s, int start, int count, int after) {

                }

                @Override
                public void onTextChanged(CharSequence s, int start, int before, int count) {

                }

                @Override
                public void afterTextChanged(Editable s) {
                    if (s.length() == 0) {
                        exchangeprofit.setOnEnabled(false);
                    } else {
                        if (!StringUtil.isEmpty(meiliView.getTextString())) {
                            exchangeprofit.setOnEnabled(true);
                        }
                    }
                }
            });

            mAdapter.addHeaderView(editTextView);
        }
        if (meiliView == null) {
            meiliView = new EditTextView(this, 1);
            mAdapter.addHeaderView(meiliView);
            meiliView.setOnEditorActionListener(new TextView.OnEditorActionListener() {
                @Override
                public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                    if (actionId == EditorInfo.IME_ACTION_DONE) {
                        if (v.getWindowToken() != null) {
                            InputMethodManager inputManager =
                                    (InputMethodManager) v.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
                            inputManager.hideSoftInputFromWindow(v.getWindowToken(), 0);
                            v.setFocusable(false);
                        }

                    }
                    return false;
                }
            });
            meiliView.addTextChangedListener(new TextWatcher() {
                @Override
                public void beforeTextChanged(CharSequence s, int start, int count, int after) {

                }

                @Override
                public void onTextChanged(CharSequence s, int start, int before, int count) {

                }

                @Override
                public void afterTextChanged(Editable s) {
                    if (s.length() == 0) {
                        exchangeprofit.setOnEnabled(false);
                        moneyTextView.setText("0.00");
                        return;
                    }
                    if (!StringUtil.isEmpty(editTextView.getTextString())) {
                        exchangeprofit.setOnEnabled(true);
                    }
                    try {
                        Double ml = Double.valueOf(s.toString());
//                        if (ml >= MINMEILI) {
                        if (ml > withdrawInfoModel.getMeili()) {
                            meiliView.setTextphone(String.valueOf(withdrawInfoModel.getMeili()));
//                                ToastUtil.show(IncomeActivity.this, IncomeActivity.this.getResources().getString(R.string.pay_maxmeili));
                        }
                        double money = ml * withdrawInfoModel.getMeiliToMoneyRatio() / 100.00;
                        if (money > maxmonoy) {
                            moneyTextView.setText(df.format(maxmonoy));
                        } else {
                            moneyTextView.setText(df.format(money));
                        }
//                        } else {
//                            ToastUtil.show(IncomeActivity.this, IncomeActivity.this.getResources().getString(R.string.profithintmeili, MINMEILI));
//                            moneyTextView.setText("0.00");
//                        }

                    } catch (Exception e) {
                        moneyTextView.setText("0.00");
                        ToastUtil.show(IncomeActivity.this, IncomeActivity.this.getResources().getString(R.string.pay_nolong));
                    }
                }
            });
        }

        if (moneyTextView == null) {
            moneyTextView = new MoneyTextView(this);
            mAdapter.addHeaderView(moneyTextView);
        }
        moneyTextView.showDouble(withdrawInfoModel.isItemDouble());
        if (bottomTips == null) {
            bottomTips = new TextView(this);
            int left = (int) getResources().getDimension(R.dimen.pro_tips_left);
            int top = (int) getResources().getDimension(R.dimen.pro_tips_top);
            bottomTips.setBackgroundColor(Color.WHITE);
            bottomTips.setPadding(left, top, left, top);
            bottomTips.setText(getResources().getString(R.string.getprofitmoneytips));
            bottomTips.setTextColor(getResources().getColor(R.color.text_b2));
            bottomTips.setGravity(Gravity.CENTER_HORIZONTAL);
            bottomTips.setTextSize(TypedValue.COMPLEX_UNIT_PX, getResources().getDimension(R.dimen.tips_size));
            mAdapter.addHeaderView(bottomTips);
        }


        if (exchangeButton == null) {
            exchangeButton = new ExchangeButton(this, 0);
            mAdapter.addFooterView(exchangeButton);
        }
        exchangeButton.setinfo(withdrawInfoModel);
        if (exchangeprofit == null) {
            exchangeprofit = new ExchangeButton(this, 1);
            mAdapter.addFooterView(exchangeprofit);
        }
        exchangeprofit.setinfo(withdrawInfoModel);
    }

    private void LoadData() {
        ProtoRequestHelper.task(ProtoHttpFactory.getwithdrawInfo()).setTag(this.hashCode()).request(new ProtoCallBack() {
            @Override
            public void onRequestSuccess(String command, String data) {
                Result<WithdrawInfoModel> result = JSON.parseObject(data, new TypeReference<Result<WithdrawInfoModel>>() {
                }.getType());
                if (result.result == CodeSuccess && result.data != null) {
                    init(result.data);
//                    final WithdrawInfoModel withdrawInfoModel = new WithdrawInfoModel();
//                    withdrawInfoModel.setIsSigned(0);
//                    withdrawInfoModel.setRealNameVerify(true);
//                    withdrawInfoModel.setBindPhone(true);
//                    withdrawInfoModel.setSignConfirmStatus(0);
//                    withdrawInfoModel.setMeili(10000);
//                    withdrawInfoModel.setMeiliToMoneyRatio(3);
//                    UserInfoModel infoModel = UserInfoCache.getUserInfo();
//                    withdrawInfoModel.setBroker(infoModel.getUser());
//                    bindView(withdrawInfoModel);


                }

            }

            @Override
            public void onRequestError(String command, int code, String message) {
            }
        });
    }
    private void registerSocketNotifySING() {
        mSocketNotifySing = new IMYTBASObject(false);
        mSocketNotifySing.stringCommand = EventHelper.EVENT_USERSIGN;
        mSocketNotifySing.setDataResultListener(new IMYTBASObject.OnDataResultListener() {
            @Override
            public void onCommandTaskSuccess(IMYTBASObject object) {
                try {
                    ProtoResult protoResult = JSON.parseObject(object.stringData, ProtoResult.class);
//                {"content":"{\"uid\":4179,\"diamond\":9999999978917,\"meili\":3682,\"meiliGain\":3832}","msg_id":341,"seq":0}
                   if (protoResult.msg_id == MessageId.accountConfirmSignReq) {
                        if (withdrawInfoModel != null) {
                            if (withdrawInfoModel.getIsSigned() == 0) {
                                withdrawInfoModel.setSignConfirmStatus(1);
                            } else {
                                withdrawInfoModel.setSignConfirmStatus(2);
                            }
                            runOnUiThread(new Runnable() {
                                @Override
                                public void run() {
                                    init(withdrawInfoModel);
                                }
                            });
                        }
                    }
                }catch (Exception e){

                }

            }
        });
        mSocketNotifySing.addEventListenWithTBASObject();
    }
    private void registerSocketNotify() {
        //监听socket
        mSocketNotify = new IMYTBASObject(false);
        mSocketNotify.stringCommand = EventHelper.EVENT_SOCK_NOTIFY;
        mSocketNotify.setDataResultListener(new IMYTBASObject.OnDataResultListener() {
            @Override
            public void onCommandTaskSuccess(IMYTBASObject object) {
                try {
//                {"content":"{\"uid\":4179,\"diamond\":9999999978917,\"meili\":3682,\"meiliGain\":3832}","msg_id":341,"seq":0}
                    if (object.socket_msg_id == MessageId.userMoneyUpdateNotify) {
                        JSONObject jsonObject = new JSONObject(object.socket_content);
                        final int meili = jsonObject.getInt("meili");
                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                if (rechargeTitle != null) {
                                    rechargeTitle.setText(meili);
                                    UserInfoModel userInfoModel = UserInfoCache.getUserInfo();
                                    if (userInfoModel != null) {
                                        UserInfoModel.MoneyModel moneyModel = userInfoModel.getMoney();
                                        if (moneyModel != null) {
                                            moneyModel.setMeili(meili);
                                            UserInfoCache.saveUserInfo(userInfoModel);
                                        }
                                    }
                                    maxmonoy = meili * withdrawInfoModel.getMeiliToMoneyRatio() / 100.00;
//                                    maxmonoy = withdrawInfoModel.isItemDouble() ? money * 2 : money;
                                    profitTitle.setText(df.format(maxmonoy));
                                }

                            }
                        });

                    }
                }catch (Exception e){

                }

            }
        });
        mSocketNotify.addEventListenWithTBASObject();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (mSocketNotify != null) {
            mSocketNotify.destroy();
        }
        if (mSocketNotifySing != null) {
            mSocketNotifySing.destroy();
        }
    }

    /**
     * 兑换按钮
     */
    private class ExchangeButton extends LinearLayout {
        int tag = 0;
//        int issign;
//        int signConfirmStatus;
//        boolean accountLocked;
//        UserModel broker;
        TextView textView;
        WithdrawInfoModel withdrawInfoModel;

        public ExchangeButton(Context context, int tag) {
            super(context);
            this.tag = tag;
            inint(context);
        }

        public void setinfo(WithdrawInfoModel withdrawInfoModel ) {
            this.withdrawInfoModel = withdrawInfoModel;
        }


        void inint(Context context) {
            setOrientation(VERTICAL);
            setBackgroundColor(Color.WHITE);
            textView = new TextView(context);
            textView.setGravity(Gravity.CENTER);
            textView.setPadding(0, (int) getResources().getDimension(R.dimen.re_button_padding), 0, (int) getResources().getDimension(R.dimen.re_button_padding));

            LayoutParams params = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            params.gravity = Gravity.CENTER_HORIZONTAL;
            params.topMargin = (int) getResources().getDimension(R.dimen.re_button_margin);
            params.bottomMargin = (int) getResources().getDimension(R.dimen.re_button_margin);
            params.leftMargin = (int) getResources().getDimension(R.dimen.re_button_margin);
            params.rightMargin = (int) getResources().getDimension(R.dimen.re_button_margin);
            setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (tag == 0) {
                        MobclickAgent.onEvent(IncomeActivity.this,"income_click_diamond");
                        BuyDiamondsActivity.start(IncomeActivity.this);
                    } else {
                        MobclickAgent.onEvent(IncomeActivity.this,"income_click_income");
                        if (withdrawInfoModel.isAccountLocked()) {
                            DialogFragmentHelper.showConfirmDialog(getSupportFragmentManager(), getResources().getString(R.string.exchangtips), getResources().getString(R.string.account_lock), new View.OnClickListener() {
                                @Override
                                public void onClick(View v) {

                                }
                            });
                            return;
                        }
                        if (reallyNameView != null) {
                            ToastUtil.show(IncomeActivity.this, getResources().getString(R.string.unbindcard));
                            return;
                        }
                        if (phoneView != null) {
                            ToastUtil.show(IncomeActivity.this, getResources().getString(R.string.unbindphone));
                            return;
                        }
                        if (withdrawInfoModel.getIsSigned() == 0) {//未签约  业余主播
                            if (StringUtil.isEmpty(editTextView.getTextString())) {
                                ToastUtil.show(IncomeActivity.this, getResources().getString(R.string.profithintNo));
                                return;
                            }
                            if (StringUtil.isEmpty(meiliView.getTextString())) {
                                ToastUtil.show(IncomeActivity.this, getResources().getString(R.string.pay_outmeili));
                                return;
                            }
                            final int meili = Integer.valueOf(meiliView.getTextString());
                            if (meili < MINMEILI) {
                                ToastUtil.show(IncomeActivity.this, getResources().getString(R.string.profithintmeili, MINMEILI));
                                return;
                            }
                            UserInfoModel userInfoModel = UserInfoCache.getUserInfo();
                            if (userInfoModel != null && userInfoModel.getUser() != null) {
                                if (userInfoModel.getUser().getLiveLevel() < 6) {
                                    DialogFragmentHelper.showConfirmDialog(getSupportFragmentManager(), getResources().getString(R.string.exchangtips), getResources().getString(R.string.exchangleveltips), new View.OnClickListener() {
                                        @Override
                                        public void onClick(View v) {

                                        }
                                    });
                                    return;
                                }
                            }
                            if (withdrawInfoModel.getSignConfirmStatus() == 0) {//未确认    只有这个条件
                                //将提醒去签约
                                DialogFragmentHelper.showConfirmDialog(getSupportFragmentManager(), "", getResources().getString(R.string.exchangeshowtip), getResources().getString(R.string.getsign_now), getResources().getString(R.string.buy_cancel), true, new View.OnClickListener() {
                                    @Override
                                    public void onClick(View v) {
                                        UserSignActivity.startActivityResult(IncomeActivity.this, 0, 0,withdrawInfoModel.getTip(), null);
                                    }
                                }, new OnClickListener() {
                                    @Override
                                    public void onClick(View v) {

                                    }
                                });

                            } else {  //默认签约经纪公司   只有这个条件 可以提现
                                DialogFragmentHelper.showConfirmDialog(getSupportFragmentManager(), "", getResources().getString(R.string.exchangeread, editTextView.getTextString(), meiliView.getTextString(), moneyTextView.getMoney()), new View.OnClickListener() {
                                    @Override
                                    public void onClick(View v) {
                                        ProtoRequestHelper.task(ProtoHttpFactory.getpaywithdraw(meili, editTextView.getTextString())).setTag(this.hashCode()).request(new ProtoCallBack() {
                                            @Override
                                            public void onRequestSuccess(String command, String data) {
                                                Result<String> result = JSON.parseObject(data, new TypeReference<Result<String>>() {
                                                }.getType());
                                                if (result.result == CodeSuccess) {
                                                    DialogFragmentHelper.showConfirmDialog(getSupportFragmentManager(), getResources().getString(R.string.exchangsuccess), getResources().getString(R.string.getmoney_success), new View.OnClickListener() {
                                                        @Override
                                                        public void onClick(View v) {

                                                        }
                                                    });
                                                    if (meiliView != null) {
                                                        meiliView.setTextphone("");
                                                        moneyTextView.setText("0.00");
                                                    }
                                                } else {
                                                    String tips = "";
                                                    if (result.result == ResultCode.CodeAccountWithdrawValueExceed) {//超出提现额度
                                                        tips = getResources().getString(R.string.getmoney_max);
                                                    } else if (result.result == ResultCode.CodeAccountWithdrawLiveTimeLimit) {//直播时间不够60分钟
                                                        tips = getResources().getString(R.string.getmoney_min);
                                                    } else if (result.result == ResultCode.CodeAccountWithdrawCountLimit) {//每日提现次数限制
                                                        tips = getResources().getString(R.string.getmoney_maxget);
                                                    } else if (result.result == ResultCode.CodeAccountMeiliNotEnough) {// 魅力不足
                                                        tips = getResources().getString(R.string.exchangeempty);
                                                    } else if (result.result == ResultCode.CodeAccountLock) {// 封号
                                                        tips = getResources().getString(R.string.account_lock);
                                                    } else {// 其他错误
                                                        tips = getResources().getString(R.string.getmoney_fail);
                                                    }
                                                    DialogFragmentHelper.showConfirmDialog(getSupportFragmentManager(), getResources().getString(R.string.exchangtips), tips, new View.OnClickListener() {
                                                        @Override
                                                        public void onClick(View v) {

                                                        }
                                                    });
                                                }
                                            }

                                            @Override
                                            public void onRequestError(String command, int code, String message) {
                                                String tips = "";
                                                if (code == ResultCode.CodeAccountWithdrawValueExceed) {//超出提现额度
                                                    tips = getResources().getString(R.string.getmoney_max);
                                                } else if (code == ResultCode.CodeAccountWithdrawLiveTimeLimit) {//直播时间不够60分钟
                                                    tips = getResources().getString(R.string.getmoney_min);
                                                } else if (code == ResultCode.CodeAccountWithdrawCountLimit) {//每日提现次数限制
                                                    tips = getResources().getString(R.string.getmoney_maxget);
                                                } else if (code == ResultCode.CodeAccountMeiliNotEnough) {// 魅力不足
                                                    tips = getResources().getString(R.string.exchangeempty);
                                                } else {// 其他错误
                                                    tips = getResources().getString(R.string.getmoney_fail);
                                                }
                                                DialogFragmentHelper.showConfirmDialog(getSupportFragmentManager(), getResources().getString(R.string.exchangtips), tips, new View.OnClickListener() {
                                                    @Override
                                                    public void onClick(View v) {

                                                    }
                                                });


                                            }
                                        });
                                    }
                                });


                            }
                        } else { //已经签约  月结主播
                            if (withdrawInfoModel.getSignConfirmStatus() == 0) {//未确认
                                //将提醒去确认签约
                                DialogFragmentHelper.showConfirmDialog(getSupportFragmentManager(), "", getResources().getString(R.string.exchangeshow_singn, withdrawInfoModel.getBroker().getNick()), getResources().getString(R.string.getsign_now), getResources().getString(R.string.buy_cancel), true, new View.OnClickListener() {
                                    @Override
                                    public void onClick(View v) {
                                        UserSignActivity.startActivityResult(IncomeActivity.this, 1, withdrawInfoModel.getSignConfirmStatus(),withdrawInfoModel.getTip(), withdrawInfoModel.getBroker());
                                    }
                                }, new OnClickListener() {
                                    @Override
                                    public void onClick(View v) {

                                    }
                                });

                            } else if (withdrawInfoModel.getSignConfirmStatus() == 2) {//已确认
                                //可以提现，但是月结只需要提现 定期月结
                                DialogFragmentHelper.showConfirmDialog(getSupportFragmentManager(), getResources().getString(R.string.getmoney_month), new View.OnClickListener() {
                                    @Override
                                    public void onClick(View v) {
                                    }
                                });
                            }
                        }


                    }
                }
            });

            if (tag == 0) {
                textView.setText(getResources().getString(R.string.exchangemeizuan));
                textView.setTextColor(Color.WHITE);
                textView.setBackground(getResources().getDrawable(R.drawable.shape_corner100_8d));
            } else {
                textView.setTextColor(getResources().getColor(R.color.text_8d));
                textView.setText(getResources().getString(R.string.exchangemoney));
                textView.setBackground(getResources().getDrawable(R.drawable.shape_sloid100_9e));
                getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
                    @Override
                    public void onGlobalLayout() {
                        getViewTreeObserver().removeOnGlobalLayoutListener(this);
                        if ((frame_layout.getHeight() - mrecyclerView.getHeight()) > 0) {
                            final View aview = new View(getContext());
                            LayoutParams paramse = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, frame_layout.getHeight() - mrecyclerView.getHeight());
                            aview.setLayoutParams(paramse);
                            aview.setBackgroundColor(Color.WHITE);
                            addView(aview);
                        }
                    }
                });
            }
            addView(textView, params);
        }

        public void setOnEnabled(boolean enabled) {
            if (tag == 1) {
//                if (enabled) {
//                    textView.setTextColor(getResources().getColor(R.color.text_8d));
//                    textView.setBackground(getResources().getDrawable(R.drawable.shape_sloid100_9e));
//                } else {
//                    textView.setBackground_fillcolor(getResources().getColor(R.color.color_b2b2b2));
//                }
            }
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == RECODE) {
            if (resultCode == Activity.RESULT_OK) {
                if (phoneView != null && withdrawInfoModel != null) {
                    withdrawInfoModel.setBindPhone(true);
                    mAdapter.removeHeaderView(phoneView);
                    phoneView = null;
                }
            }
        } else if (requestCode == RECARDCODE) {
            if (resultCode == Activity.RESULT_OK) {
                if (reallyNameView != null && withdrawInfoModel != null) {
                    withdrawInfoModel.setRealNameVerify(true);
                    mAdapter.removeHeaderView(reallyNameView);
                    reallyNameView = null;
                }
            }
        }
    }
    @Override
    protected void onResume() {
        super.onResume();
        MobclickAgent.onResume(this);
    }

    @Override
    protected void onPause() {
        super.onPause();
        MobclickAgent.onPause(this);
    }
}
